package cn.com.roy.thread.t4_1_12.lockmethodtest2;

import java.util.concurrent.locks.ReentrantLock;

public class MyService {
    private ReentrantLock lock;
    public MyService(boolean fair){
        this.lock = new ReentrantLock(fair);
    }

    public void testMethod(){
        try {
            System.out.println(lock.isHeldByCurrentThread()) ; //判断当前线程是否保持此锁定
            lock.lock();
            System.out.println(lock.isHeldByCurrentThread()) ;
        } finally {
            lock.unlock();
        }
    }



}
